/******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
* File Name          : COMM_SERVER.h
* Author             : MCD Application Team
* Version            : V3.3.0
* Date               : 21-March-2011
* Description        : Custom HID demo configuration file
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __COMMUNI_SERVER_H
#define __COMMUNI_SERVER_H

#ifdef __cplusplus
 extern "C" {
#endif

/**
  * @brief GLOBALS RAM definition
  */
#ifdef   COMMUNI_SERVER_GLOBALS
#define  COMMUNI_SERVER_EXT
#else
#define  COMMUNI_SERVER_EXT  extern
#endif


/*************************************************************************************************
 *                                        通信规范定义
 *************************************************************************************************/
/* 数据末尾关键字段，用于判定当前数据包是否已解析，1表示新包未解析 */
#define COMMRecdataType_Null                 0
#define COMMRecdataType_Full                 1

/* 通信状态 */
#define GenCommStaBFOrd_TXDataNumber         0
#define GenCommStaBFOrd_TOTNum               1
#define GenCommStaBFOrd_CommNum              (GenCommStaBFOrd_TXDataNumber+1)
COMMUNI_SERVER_EXT uint16_t USBCommStatusBuffer[GenCommStaBFOrd_CommNum];
COMMUNI_SERVER_EXT uint16_t RS232CommStatusBuffer[GenCommStaBFOrd_CommNum];

/* 工作流返回值 */
#define CommDealReturnCode_Null              0
#define CommDealReturnCode_MemoryUpd         DEF_BIT_00
#define CommDealReturnCode_WorkFlowReq       DEF_BIT_01
#define CommDealReturnCode_MsgTX             DEF_BIT_02
#define CommDealReturnCode_SpecialCfg        DEF_BIT_03

/* 通信媒介 */
#define CommTypeOrd_USB                      0
#define CommTypeOrd_RS232                    1
#define CommTypeOrd_RS485                    2
#define CommTypeOrd_BTH                      3
#define CommTypeOrd_TOTNum                   4

/* 通信指令 */
#define COMMCommandType_Cfg36                0x36
#define COMMCommandType_Cfg37                0x37
#define COMMCommandType_Cfg38                0x38
#define COMMCommandType_Cfg40                0x40
#define COMMCommandType_Cfg41                0x41

/* 通信指令范围 */
#define USBCommFunctionCodeRange_Min         COMMCommandType_Cfg36
#define USBCommFunctionCodeRange_Max         COMMCommandType_Cfg41

/* 通信格式 */
#define CommPTCByteSize_ID                   1
#define CommPTCByteSize_FunCode              1
#define CommPTCByteSize_Length               2
#define CommPTCByteSize_STRPack              (CommPTCByteSize_ID+CommPTCByteSize_FunCode+CommPTCByteSize_Length)  /* 4 */
#define CommPTCByteSize_ATCmdPack            1

/* Modbus规范 */
#define CommPTCByteSize_Adr                  2
#define CommPTCByteSize_Num                  1
#define CommPTCByteSize_OperaPack            (CommPTCByteSize_Adr+CommPTCByteSize_Num)    /* 3 */

/* 波形规范 */
#define CommPTCByteSize_LineName             1
#define CommPTCByteSize_LineValue            4
#define CommPTCByteSize_PrintPack            (CommPTCByteSize_LineName+CommPTCByteSize_LineValue)    /* 5 */

/* 返回值规范 */
#define CommReturnMSGCode_Success            0x01
#define CommReturnMSGCode_OutOfRange         0x02
#define CommReturnMSGCode_ReadOnly           0x03
#define CommReturnMSGCode_NoAuthority        0x04

/*************************************************************************************************
 *                                        通信堆栈
 *************************************************************************************************/
/* USB */
#define USBRXBufferDataTOTNum   896
COMMUNI_SERVER_EXT uint8_t  USBRXBufferData[USBRXBufferDataTOTNum];
COMMUNI_SERVER_EXT uint16_t USBRXBufferCount;
#define USBTXBufferDataTOTNum   896
COMMUNI_SERVER_EXT uint8_t  USBTXBufferData[USBTXBufferDataTOTNum];

/* RS232 */
#define RS232RXBufferDataTOTNum   896
COMMUNI_SERVER_EXT uint8_t  RS232RXBufferData[RS232RXBufferDataTOTNum];
COMMUNI_SERVER_EXT uint16_t RS232RXBufferCount;
#define RS232TXBufferDataTOTNum   896
COMMUNI_SERVER_EXT uint8_t  RS232TXBufferData[RS232TXBufferDataTOTNum];

/* RS485 */
#define RS485RXBufferDataTOTNum   256
COMMUNI_SERVER_EXT uint8_t  RS485RXBufferData[RS485RXBufferDataTOTNum];
COMMUNI_SERVER_EXT uint16_t RS485RXBufferCount;
#define RS485TXBufferDataTOTNum   256
COMMUNI_SERVER_EXT uint8_t  RS485TXBufferData[RS485TXBufferDataTOTNum];

/*************************************************************************************************
 *                                        接口函数
 *************************************************************************************************/
/**
  * @brief  USB communication
  * @param  none
  * @return none.
  * @Caller This is a task. 
  */
uint8_t Communi_USBserver(void);
uint8_t Communi_RS485server(void);
uint8_t Communi_RS232server(void);
void USBDateSendCOMM_handling(uint8_t *Point,uint16_t DataNumber);


#ifdef __cplusplus
}
#endif

#endif /*__COMMUNI_SERVER_H*/

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/